package com.myx.design.single.attack;

/**
 * 描述: 预防单例模式反射攻击
 * @author: myx
 * @date: 2018/11/28
 * Copyright © 2018-hotpot. All rights reserved.
 */
public class SingleAttack {
    private static boolean flag=false;
    private static SingleAttack singleAttack =new SingleAttack();
    private SingleAttack(){
        System.out.println("构造函数");
        if(!flag){
            flag=true;
        }else{
            throw new RuntimeException("单例模式再被反射攻击");
        }
    }
    public static SingleAttack getInstance(){
        return singleAttack;
    }
}
